package com.ds.seqlist.LeetCode;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
 * @author Dianzhi Han
 * @version 1.0
 * @description: TODO
 * @date 2022/10/21 1:33
 */
public class Num125_IsPalindrome {
    public boolean isPalindrome(String s) {
        if(Objects.equals(s, "")){
            return false;
        }
        List<Character> ret=remove(s);
        List<Character> ret2 = new ArrayList<>(ret);
        Collections.reverse(ret);
        if(ret2.equals(ret)){
            return true;
        }
        return false;

    }

    public  List<Character> remove(String s){
        s = s.toLowerCase();
        char[] temp = s.toCharArray();
        List<Character> list = new ArrayList<>();
        for(int i = 0; i<temp.length ; i++){
            if(temp[i] <= 'z' && temp[i] >= 'a' || temp[i] <= '9' && temp[i] >= '0'){
                list.add(temp[i]);
            }
        }
        return list;
    }
}
